package mka.puzzle;

import mka.puzzle.shape.SimpleCircle;
import mka.puzzle.shape.SimpleRectangle;
import mka.puzzle.shape.SimpleShape;
import mka.puzzle.shape.SimpleSquare;
import mka.puzzle.util.FunctionShape;

public class Puzzle {

	private int typeShapePuzzle;

	private double areaPuzzle;

	private double numberPieces;

	public Puzzle() {
		int temp = FunctionShape.randNumber(10) * 10;
		if (temp == 0){
			temp = 1;
		}
		SimpleSquare sq = new SimpleSquare(FunctionShape.randNumber(10) * 10);
		areaPuzzle = sq.getArea();
	}

	public Puzzle(int type) {
		switch (type) {
		case 0:
			SimpleRectangle rec = new SimpleRectangle(FunctionShape.randNumber(10),
					FunctionShape.randNumber(10));
			areaPuzzle = rec.getArea();
			typeShapePuzzle = 0;
			break;
		case 1:
			SimpleSquare square = new SimpleSquare(FunctionShape.randNumber(10));
			areaPuzzle = square.getArea();
			typeShapePuzzle = 1;
			break;
		case 2:
			SimpleCircle cir = new SimpleCircle(FunctionShape.randNumber(10));
			areaPuzzle = cir.getArea();
			typeShapePuzzle = 2;
			break;
		default:
			areaPuzzle = 1;
			break;
		}
	}

	public double getArea() {
		return areaPuzzle;
	}

	/**
	 * getNumberPieces. 
	 * So luong mieng can lat tren mot hinh dien tich cho truoc.
	 * 
	 * @param s
	 * @return double
	 */
	public double getNumberPieces(SimpleShape s) {
		String typeShape = s.getName();
		if ("Rectangle".equals(typeShape)) {
			numberPieces = areaPuzzle / s.getArea();
		} else if ("Square".equals(typeShape)) {
			if (typeShapePuzzle == 0) {
				numberPieces = areaPuzzle / s.getArea();
			} else if (typeShapePuzzle == 1) {
				numberPieces = areaPuzzle / s.getArea();
			}
		} else if ("Circle".equals(typeShape)) {
			numberPieces = 0;
		}
		return numberPieces;
	}

}
